
package com.caigua.mgp.mg.codegen.customize.xmlmapper.elements;

import com.caigua.mgp.mg.internal.CustomizeIntrospectedTableMyBatis3Impl;
import com.caigua.mgp.mg.utils.GenUtil;
import org.mybatis.generator.api.dom.xml.Attribute;
import org.mybatis.generator.api.dom.xml.TextElement;
import org.mybatis.generator.api.dom.xml.XmlElement;

public class CustomizeQueryPageElementGenerator extends CustomizeAbstractXmlElementGenerator {
    public CustomizeQueryPageElementGenerator() {
    }

    public void addElements(XmlElement parentElement) {
        XmlElement answer = new XmlElement("select");
        answer.addAttribute(new Attribute("id", ((CustomizeIntrospectedTableMyBatis3Impl)this.introspectedTable).getQueryPage()));
        answer.addAttribute(new Attribute("resultMap", this.introspectedTable.getBaseResultMapId()));
        String parameterType = GenUtil.pageParamClass.toString();
        answer.addAttribute(new Attribute("parameterType", parameterType));
        this.context.getCommentGenerator().addComment(answer);
        StringBuilder sb = new StringBuilder();
        sb.append("select ");
        answer.addElement(new TextElement(sb.toString()));
        answer.addElement(this.getBaseColumnListElement());
        sb.setLength(0);
        sb.append("from ");
        sb.append(this.introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());
        answer.addElement(new TextElement(sb.toString()));
        answer.addElement(this.getListPageFilterElement());
        answer.addElement(this.getListPageSortElement());
        if (this.context.getPlugins().sqlMapSelectByPrimaryKeyElementGenerated(answer, this.introspectedTable)) {
            parentElement.addElement(answer);
        }

        parentElement.addElement(this.getListPageFilterSqlElement());
        parentElement.addElement(this.getListPageSortSqlElement());
    }
}
